/****************************************
 * 2018 - 2021 版权所有 CopyRight(c) 快程乐码信息科技有限公司所有, 未经授权，不得复制、转发
 */

package com.kclm.security.demo.service.impl;

import com.kclm.security.demo.entity.Group;
import com.kclm.security.demo.entity.Role;
import com.kclm.security.demo.mapper.GroupMapper;
import com.kclm.security.demo.mapper.RoleMapper;
import com.kclm.security.demo.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/******************
 * @Author yejf
 * @Version v1.0
 * @Create 2020-07-20 17:25
 * @Description TODO
 */
@Service
@Slf4j
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private GroupMapper groupMapper;

    @Override
    public int save(Role role) {
        log.debug("--持久化角色对象");
        return this.roleMapper.save(role);
    }

    @Override
    public List<Role> findAll() {
        log.debug("查询出所有的角色信息");
        return this.roleMapper.selectAll();
    }

    @Override
    public List<Role> findRolesByGroupId(Serializable groupId) {
        //
        log.debug("查询组ID为：%s 下的所有角色信息", groupId);
        //
        final List<Group> groups = this.groupMapper.selectRolesByGroupId(groupId);
        //
        if(groups != null && groups.size() > 0) {
            //
            return groups.get(0).getRoles();
        }
        //
        return null;
    }
}
